Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-116381: Remove bad specializations, add fail stats #116464

Merged
merged 3 commits into from
Mar 7, 2024

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Mar 7, 2024

Partially reverts some of the bad specializations in #116385. Stats for what are "bad" are from https://github.com/faster-cpython/benchmarking-public/tree/main/results/bm-20240307-3.13.0a4%2B-72dbea2.

@Fidget-Spinner Fidget-Spinner changed the title Remove bad specializations, add fail stats gh-116381: Remove bad specializations, add fail stats Mar 7, 2024
@bedevere-app bedevere-app bot mentioned this pull request Mar 7, 2024
Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stats gathering needs tidying up a bit, but LGTM otherwise


#ifdef Py_STATS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this into its own function, like load_attr_fail_kind, then this becomes SPECIALIZATION_FAIL(CONTAINS_OP, contains_fail_kind(value))


#ifdef Py_STATS
if (PyUnicode_CheckExact(value)) {
SPECIALIZATION_FAIL(TO_BOOL, SPEC_FAIL_CONTAINS_OP_STR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TO_BOOL -> CONTAINS_OP and a few more times below

inst(CONTAINS_OP_STR, (unused/1, left, right -- b)) {
DEOPT_IF(!PyUnicode_CheckExact(right));
int res = PyUnicode_Contains(right, left);
inst(CONTAINS_OP_MAPPINGPROXY, (unused/1, left, right -- b)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that this is worthwhile.
OOI, what are the numbers for this?

Copy link
Member Author

@Fidget-Spinner Fidget-Spinner Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be. I might just remove it.
On python -m test_typing test_re test_dis test_zlib., I get:

frozenset:278
tuple:261
dict:256
list:225
set:150
str:143
mappingproxy:62
dict_values:9
EnumDict:5
collections.OrderedDict:5
collections.defaultdict:4
_Environ:3

Copy link
Member Author

@Fidget-Spinner Fidget-Spinner Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I'm not specializing for tuple or list because it's dominated by searching up through the collection anyways so it's not worth it. The rest are O(1) so maybe worth to cut the constant factor.

@bedevere-app
Copy link

bedevere-app bot commented Mar 7, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@gvanrossum gvanrossum removed their request for review March 7, 2024 15:44
@gvanrossum
Copy link
Member

I'll leave this between the two of you. (TBH I didn't mean for you to merge gh-116385, I should have been clearer -- I was signing off but expected Mark to have something to say and was hoping for a benchmark.)

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@Fidget-Spinner Fidget-Spinner merged commit 41457c7 into python:main Mar 7, 2024
58 of 59 checks passed
@Fidget-Spinner Fidget-Spinner deleted the spec_contains_op_fix branch March 7, 2024 16:21
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants